<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3_字符串形式refs</title>
</head>

<body>
    <div id="test"></div>
    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom库 -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入babel 转换jsx的库 -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入PropType库  min没有警告-->
    <script type="text/javascript" src="../js/prop-types.js"></script>

    <script type="text/babel">/* 此处要写babel */
        // 创建组件
        class Demo extends React.Component {
            // 展示数据
            showData = () => {
                const { input1 } = this.refs
                console.log(input1.value)
            }
            showData2 = () => {
                const { input2 } = this.refs
                console.log(input2.value)
            }
            render() {
                return (
                    <div>
                        <input type="text" ref="input1" placeholder="点击按钮提示数据" />
                        <button ref="button1" onClick={this.showData}>点击按钮提示数据</button>
                        <input type="text" ref="input2" onBlur={this.showData2} placeholder="失去焦点提示数据" />
                    </div>
                )
            }
        }

        const root = ReactDOM.createRoot(document.getElementById('test'));
        root.render(<Demo />);


    </script>
</body>

</html>